import { parserBaseSymbol, parserQuoteSymbol } from "./util";

type PriceMap = Record<string, number>;
/**
 * 价格转换成USDT
 */
export class PriceConverter {
  private quotePrices: PriceMap;
  private exchange: string;
  constructor(exchange: string) {
    this.quotePrices = {
      USDT: 1,
      BTC: 30238,
      ETH: 1891
    };
    this.exchange = exchange;
  }

  public setPrice(quoteSymbol: string, price: number) {
    this.quotePrices[quoteSymbol] = price;
  }
  public setBaseSymbolPrice(symbol: string, price: number) {
    this.setPrice(parserBaseSymbol(symbol), price)
  }
  public getPriceIndex(symbol: string) {
    const quoteSymbol = parserQuoteSymbol(symbol);
    return this.quotePrices[quoteSymbol] ? this.quotePrices[quoteSymbol] : 1;
  }
  public getBasePrice(symbol: string) {
    const base = parserBaseSymbol(symbol);
    return this.quotePrices[base] ? this.quotePrices[base] : 0;
  }
}